<?php
namespace Home\Controller;
use Home\Common\Common;
class InterviewinfoController extends Common{
    public function index()
    {
        $resumeinfo = M('resumeinfo');
        $rest = $resumeinfo->where('state=1')->select();
        if (empty($rest)) {
            $this->error('还没有人投简历哦');
        } else {
            $interviewinfo = M('interviewinfo');
            if (empty($_GET['search'])) {
                $where = array('interviewinfo.states'=>1);
            } else {
                $where = array('`rmn_men` like "%' . $_GET['value'] . '%" or `itw_post` like "%' . $_GET['value'].'%"','interviewinfo.states'=>1);
                $this->assign('value', $_GET['value']);
            }
            $count = $interviewinfo->join('resumeinfo on resumeinfo.rmn_id=interviewinfo.rmn_id')->where($where)->count();
            $page = new \Think\Page($count, 4);
            $show = $page->show();
            $list = $interviewinfo->join('resumeinfo on resumeinfo.rmn_id=interviewinfo.rmn_id')->where($where)->limit($page->firstRow . ',' . $page->listRows)->order('itw_id')->select();
            $pst=  M('postinfo');
            $lis=$pst->select();
            $this->assign('count', $count);
            $this->assign('show', $show);
            $this->assign('list', $list);
            $this->assign('rest', $rest);
            $this->assign('lis', $lis);
            $this->display();
        }
    }

    public function del(){
        if(empty($_GET['itw_id'])){
            $this->error('参数错误',U('index'));
        }
        else{
            $intervie=M('interviewinfo');
            $intervie->where('`itw_id`='.$_GET['itw_id'])->save(array('states'=>0));
            $this->success('成功隐藏了面试信息',U('index'));
        }
    }
    public function new_select(){
            $rem=M('resumeinfo');
            $info=$rem->where('rmn_id='.$_GET['rmn_id'])->find();
            $this->assign('info',$info);
            $this->display();
    }
    //根据下啦框值的改变获取值
    public function submit_api(){
        $resumeinfo = M('resumeinfo');
        $rest = $resumeinfo->where('state=1 and rmn_id='.$_GET['rmn_id'])->find();
        $this->ajaxReturn($rest);
    }
    public function submit(){
        if (empty($_POST['submit'])) {
            $staf=  M('postinfo');
            $interv=M('interviewinfo');
            $resumeinfo = M('resumeinfo');
            $sss=$interv->select();
            $sta=$staf->select();
            $rest = $resumeinfo->where('resumeinfo.state=1')->select();
            $this->assign('sss',$sss);
            $this->assign('sta',$sta);
            $this->assign('rest',$rest);
            $this->display();
        }else{
            $intrv = M('interviewinfo');
            if (empty($_POST['rmn_men']))$this->error('面试人不能为空',U('submit'));
            $intrv->add($_POST);
            $this->success('通知面试成功，请关注情况',U('index'));
        }

    }
    //回收站
    public function new_index()
    {
        $resumeinfo = M('resumeinfo');
        $rest = $resumeinfo->where('state=1')->select();
        if (empty($rest)) {
            $this->error('还没有人投简历哦');
        } else {
            $interviewinfo = M('interviewinfo');
            if (empty($_GET['search'])) {
                $where = array('interviewinfo.states'=>0);
            } else {
                $where = array('`rmn_men` like "%' . $_GET['value'] . '%" or `itw_post` like "%' . $_GET['value'].'%"','interviewinfo.states'=>0);
                $this->assign('value', $_GET['value']);
            }
            $count = $interviewinfo->join('resumeinfo on resumeinfo.rmn_id=interviewinfo.rmn_id')->where($where)->count();
            $page = new \Think\Page($count, 4);
            $show = $page->show();
            $list = $interviewinfo->join('resumeinfo on resumeinfo.rmn_id=interviewinfo.rmn_id')->where($where)->limit($page->firstRow . ',' . $page->listRows)->order('itw_id')->select();
            $this->assign('count', $count);
            $this->assign('show', $show);
            $this->assign('list', $list);
            $this->assign('rest', $rest);
            $this->display();
        }
    }
    //批量隐藏
    public function hide_all(){
        $intvi= M('interviewinfo');
        if(empty($_GET['itw_id'])){
            $this->error('请选择需要隐藏的内容',U('index'));
        }
        $it_id= implode(',',$_GET['itw_id']);//获取id
        $str = explode(",",$it_id);//去逗号
        foreach ($str as $a){//循环id
            $intvi->where(array('itw_id'=>$a))->save(array('states'=>0));
        }
        $this->success('隐藏成功',U('index'));
    }
//删除
    public function delete(){
        if(empty($_GET['itw_id'])){
            $this->error('参数错误',U('index'));
        }
        else{
            $intervie=M('interviewinfo');
            $intervie->where('`itw_id`='.$_GET['itw_id'])->delete();
            $this->success('成功删除了面试信息',U('index'));
        }
    }
//显示
    public function new_xiansi(){
        if(empty($_GET['itw_id'])){
            $this->error('参数错误',U('index'));
        }
        else{
            $intervie=M('interviewinfo');
            $intervie->where('`itw_id`='.$_GET['itw_id'])->save(array('states'=>1));
            $this->success('成功显示了面试信息',U('index'));
        }
    }
    //清空
    public function del_all(){
        $intvi= M('interviewinfo');
        if(empty($_GET['itw_id'])){
            $this->error('请选择内容',U('index'));
        }
        $it_id= implode(',',$_GET['itw_id']);//获取id
        $str = explode(",",$it_id);//去逗号
        foreach ($str as $a){//循环id
            $intvi->where(array('itw_id'=>$a))->delete();
        }
        $this->success('清空成功',U('index'));
    }
    public function shenhe(){
         if (empty($_POST['submit'])){
             if (empty($_GET['itw_id'])) {
                 $this->error('参数错误', U('index'));
             }
             $inter = M('interviewinfo');
             $list=$inter->where('`itw_id`='.$_GET['itw_id'])->select();
             if($list[0]['status']==1){
                 $this->error('已经审核过了',U('index'));
             }
             $info = $inter->where('`itw_id`='.$_GET['itw_id'])->find();
             $this->assign('info',$info);
             $this->display();
         }else{
             $nter = D('interviewinfo');
             $nter->where('`itw_id`='.$_POST['itw_id'])->save($_POST);
             $this->success('审核完成',U('index'));
         }
    }

}